package com.ty.service;

import com.ty.mapper.GameMapper;
import com.ty.mapper.TeamMapper;
import com.ty.pojo.Game;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 赛程管理的业务逻辑
 * 在这里可以进行连接查询，也可以在mybatis.xml中进行配置
 *
 * @author 田野
 */
@Service
public class GameService {

    @Resource
    private TeamMapper teamMapper;

    @Resource
    private GameMapper gameMapper;

    @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
    public List<Game> queryAll() {
        List<Game> games = gameMapper.selectByExample(null);
        for (Game game : games) {
            // 根据主队id查询到的助对象系赋值给当前的赛程
            game.setHomeTeam(teamMapper.selectByPrimaryKey(game.getHomeTeamId()));
            game.setVisitingTeam(teamMapper.selectByPrimaryKey(game.getVisitingTeamId()));
        }
        return games;
    }

}
